package org.example.spring.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.spring.domain.dto.OrderDTO;
import org.example.spring.domain.pojo.Order;
import org.example.spring.domain.pojo.OrderDetail;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Mapper
public interface OrderMapper {
    ArrayList<Order> getOrderByStatus(Integer status);

    @Update("UPDATE orders SET status = #{status} WHERE order_id = #{orderId}")
    void updateOrderStatus(Integer orderId, Integer status);

    @Select("SELECT * FROM order_details WHERE order_id = #{orderId}")
    ArrayList<OrderDetail> getOrderDetailByOrderId(Integer orderId);

    void addOrder(Order order);

    @Update("UPDATE orders SET status = 1 WHERE order_id = #{orderId}")
    void pay(Integer orderId);

    @Update("UPDATE orders SET status = 5 WHERE status = 0 AND order_date < #{time}")
    void cancelTimeoutOrders(LocalDateTime time);

    Page<Order> getOrdersByPage(OrderDTO orderDTO);
    @Select("select * from orders where user_id=#{userId}")
    List<Order> list(Integer userId);

}
